<?php
require("frmCookie.php");

$codigoModelo =$_GET['codigo'];

$sql = "select b.idboletin, b.numero, b.nombre, b.fecha from boletines b join modelosxboletin mxb on b.idboletin = mxb.idboletin where idmodelo = (select idmodelo from modelos where codigo = '$codigoModelo')";

$resultBoletines = readSQL($sql);

?>
<html>
	<head>
    	<?php
			require("frmHeader.php");
		?>
    	<script language="javascript">
			self.moveTo(350,0);
			
			function verBoletin(idBoletin)
			{
				var url = "modelosDetallesBoletinShow.php?idBoletin=" + idBoletin;
				window.open(url,'frmShowDetallesBoletin','width=600,height=380,scrollbars=yes,menubar=no,titlebar=no,resizable=yes','');
			}
			
			function aplicarBoletin(idBoletin)
			{
				window.opener.aplicarBoletin(idBoletin);
			}
		</script>
    </head>
	<body>
    <table cellpadding="0" cellspacing="0" align="center" class="tablaPrincipal">
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="contenedorPrincipal">
                    	<tr>
                        	<td align="center" class="tituloPantalla" colspan="6">
								<p class="texto">Boletines de Servicio</p>
                            </td>
                        </tr>
                        <?php
						if(count($resultBoletines)>0)
						{
						?>
                            <tr>
                                <th align="left" width="28%">
                                    Boletin #
                                </th>
                                <th align="left" width="28%">
                                    Nombre
                                </th>
                                <th align="left" width="28%">
                                    Fecha
                                </th>
                                <th align="left" width="16%">&nbsp;
                                    
                                </th>
                            </tr>
                            <tr>
                                <td width="50%" valign="top" colspan="5">
                                    <table width="100%">
                                        <?php
                                        $i=0;
                                        foreach($resultBoletines as $valueBoletines)
                                        {
                                            if($i%2==0)
                                            {
                                                $claseFila = "par";
                                            }
                                            else
                                            {
                                                $claseFila = "impar";	
                                            }
                                            echo "<tr class='$claseFila'>";
                                                echo "<td width='28%'>";
                                                    echo $valueBoletines['numero'];
                                                echo "</td>";
                                                echo "<td width='28%'>";
                                                    echo $valueBoletines['nombre'];	
                                                echo "</td>";
                                                echo "<td width='28%'>";
                                                    echo $valueBoletines['fecha'];	
                                                echo "</td>";
                                                echo "<td width='16%' align='rigth'>";
                                                    ?>
                                                    <input type="button" name="btnVer" value="Ver" onClick="verBoletin(<?php echo $valueBoletines['idboletin'];?>);"/>
                                                    <input type="button" name="btnAplicar" value="Aplicar" onClick="aplicarBoletin(<?php echo $valueBoletines['idboletin'];?>);"/>
                                                    <?php	
                                                echo "</td>";
                                            echo "</tr>";
                                            $i++;
                                        }
                                        ?>
                                    </table>
                                </td>
                            </tr>
                        <?php
						}
						else
						{
						?>
                        <tr>
                        	<td>
                            	No exiten Boletines de Servicio para este Modelo.
                            </td>
                        </tr>
                        <?php	
						}
						?>
                    </table>
                </td>
            </tr>
        </table>
	</body>
</html>